package zz;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.lang.reflect.Array;
import java.util.ArrayList;

public class seriable {
    public static void main(String[] args) throws Exception {
        /*ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("c.txt"));
        oos.writeObject(new Person("zxc",21));
        oos.close();
        ObjectInputStream ois = new ObjectInputStream(new FileInputStream("c.txt"));
        Object o = ois.readObject();
        System.out.println(o);
        ois.close();*/
        ArrayList<Person> list = new ArrayList<Person>();
        list.add(new Person("zc", 21));
        list.add(new Person("zfsac", 321));
        list.add(new Person("zfdzc", 211));
        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("c.txt"));
        oos.writeObject(list);
        ObjectInputStream ois = new ObjectInputStream(new FileInputStream("c.txt"));
        Object o = null;
        ArrayList<Person> lsit2 = new ArrayList<>();
        Object o1 = ois.readObject();

        list= (ArrayList<Person>)o1;
        for (Person person : list) {
            System.out.println(person);
        }
        oos.close();
        ois.close();
    }
}
